//
//  DiscoverCell.m
//  Mango
//
//  Created by lanou3g on 16/5/11.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "DiscoverCell.h"

@interface DiscoverCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageVIew;
@property (weak, nonatomic) IBOutlet UIImageView *coverImageVIew;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *readnumLabel;

@end


@implementation DiscoverCell

- (void)setModel:(LeftModel *)model {
    if (_model != model) {
        _model = model;
       NSString *coverPic = [model.pic componentsSeparatedByString:@"!"][0];
        [self.coverImageVIew sd_setImageWithURL:[NSURL URLWithString:coverPic] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.nameLabel.text = model.author[@"name"];
        self.titleLabel.text = model.title;
        self.readnumLabel.text = [NSString stringWithFormat:@"%@ / %ld阅读",model.author[@"name"],model.readnum];
        if (model.author[@"pic"]) {
            [self setValueWithDict:model.author];
        }else {
            [self.iconImageVIew sd_setImageWithURL:[NSURL URLWithString:model.cat[@"pic"]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        }
    }
}

- (void)setValueWithDict:(NSDictionary *)dict {
    NSString *iconPic = [dict[@"pic"] componentsSeparatedByString:@"?"][0];
    [self.iconImageVIew sd_setImageWithURL:[NSURL URLWithString:iconPic] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
}
- (void)awakeFromNib {
    self.iconImageVIew.layer.cornerRadius = 14;
    self.iconImageVIew.layer.masksToBounds = YES;
}

#pragma mark 切换至日间模式
-(void)updateToDaySkinMode {
    self.nameLabel.textColor = [UIColor blackColor];
    self.titleLabel.textColor = [UIColor blackColor];
    self.readnumLabel.textColor = [UIColor blackColor];
    self.contentView.backgroundColor = [UIColor whiteColor];
}

-(void)updateToNightSkinMode {
    self.nameLabel.textColor = [UIColor grayColor];
    self.titleLabel.textColor = [UIColor grayColor];
    self.readnumLabel.textColor = [UIColor grayColor];
    self.contentView.backgroundColor = [UIColor colorWithRed:42/255.0 green:39/255.0 blue:43/255.0 alpha:1.0];
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
